<template>
  <div class="admin-reward-sidebar">
    <ul class="reward-sidebar_ul" v-if="async">
      <li class="reward-sidebar_li" v-for="(item,index) in sidebarValue.links" :key="index" :class="{'reward-sidebar_active': index == sidebarIndex}" @click="sidebarTo(item, index)">
        <div class="reward-sidebar_text">{{item.name}}</div>
      </li>
    </ul>
  </div>
</template>

<script>
  import sidebar from './sidebar.json'
  import './var.scss'

  import ala from 'ala'
export default {
    data () {
      return {
        sidebarIndex: 0,
        async: false,
        sidebarValue: ''
      }
    },
    props: {
      widget: {}
    },
    mounted () {
      this.init()
    },
    methods: {
      async init () {
        if (this.$route.query.moduleId !== undefined) {
          this.sidebarValue = sidebar[0]
          var id = ala.urlQuery('moduleId')
        } else if (this.$route.query.id !== undefined) {
          this.sidebarValue = sidebar[1]
          var id = ala.urlQuery('id')
        }
        this.sidebarValue.links.forEach(r => { 
           if (r.url.indexOf('moduleId') > 0) {
            var url = r.url.substring(0,r.url.indexOf('='))
            r.url = url + '=' + id
           } else if (r.url.indexOf('id') > 0) {
            var url = r.url.substring(0,r.url.indexOf('='))
            r.url = url + '=' + id
           } 
        }) 
        this.async = true
      },
      sidebarTo (val, index) {
        this.$router.push(val.url)
        this.sidebarIndex = index
      }
    }
  }
</script>
